﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Unity;
using Silverlight.Weblog.Client.DAL.RiaServices;
using Silverlight.Weblog.Common.IoC;

namespace Silverlight.Weblog.Client.DAL.Services
{
    [Export(typeof(IInitializationService))]
    public class NavigationFragmentDataRetrivelService : IInitializationService
    {
        public NavigationFragmentDataRetrivelService()
        {
            IoC.BuildUp(this);
        }

        [Dependency]
        public IInitialPaylodService InitialPaylodService { get; set; }

        #region Implementation of IApplicationService

        public void StartService(ApplicationServiceContext context)
        {
            
        }

        public void Initialize()
        {
         //   Application.Current.Host.NavigationStateChanged += new EventHandler<System.Windows.Interop.NavigationStateChangedEventArgs>(Host_NavigationStateChanged);
        }

        void Host_NavigationStateChanged(object sender, System.Windows.Interop.NavigationStateChangedEventArgs e)
        {
            List<string> SendToServerForFragments = new List<string>() { "Search", "BlogPost", "Home", "Category"};
            if (SendToServerForFragments.Any(str => e.NewNavigationState.StartsWith(str)))
            {
                InitialPaylodService.Load();
            }
        }

        public void StopService()
        {
        //    Application.Current.Host.NavigationStateChanged -= new EventHandler<System.Windows.Interop.NavigationStateChangedEventArgs>(Host_NavigationStateChanged);
        }



        #endregion
    }
}
